import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class Order {
    private String orderId;
    private List<Ticket> tickets;
    private double totalAmount;
    private Date createTime;
    private int payStatus;
    private String customerName;
    private String operator;
    public Order(String operator, String customerName) {
        this.orderId = generateOrderId();
        this.tickets = new ArrayList<>();
        this.createTime = new Date();
        this.payStatus = 0;
        this.operator = operator;
        this.customerName = customerName;
        this.totalAmount = 0.0;
    }
    private String generateOrderId() {
        String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
        String timestamp = String.valueOf(System.currentTimeMillis()).substring(5);
        return "ORDER_" + uuid + timestamp;
    }
    public void addTicket(Ticket ticket) {
        tickets.add(ticket);
        totalAmount += ticket.getPrice();
    }
    public boolean pay() {
        if (payStatus == 1) {
            System.out.println("该订单已支付，无需重复支付");
            return false;
        }
        payStatus = 1;
        System.out.println("订单支付成功！总金额：" + totalAmount + "元");
        return true;
    }
    public boolean cancel() {
        if (payStatus == 1) {
            System.out.println("已支付订单无法取消，请走退票流程");
            return false;
        }
        tickets.clear();
        totalAmount = 0;
        System.out.println("订单已取消");
        return true;
    }
    public void printOrderInfo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("\n====================订单详情====================");
        System.out.println("订单号：" + orderId);
        System.out.println("下单时间：" + sdf.format(createTime));
        System.out.println("购买人：" + (customerName.isEmpty() ? "未知" : customerName));
        System.out.println("操作人：" + operator);
        System.out.println("支付状态：" + (payStatus == 0 ? "未支付" : "已支付"));
        System.out.println("总金额：" + totalAmount + "元");
        System.out.println("包含票数：" + tickets.size() + "张");
        System.out.println("------------------------------------------------");
        for (Ticket ticket : tickets) {
            System.out.println("票号：" + ticket.getTicketId() + "，座位：" + ticket.getSeat().getSeatLabel());
        }
        System.out.println("================================================");
    }
    public String getOrderId() {
        return orderId;
    }
    public List<Ticket> getTickets() {
        return tickets;
    }
    public double getTotalAmount() {
        return totalAmount;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public int getPayStatus() {
        return payStatus;
    }
    public String getOperator() {
        return operator;
    }
}
